package umd.mhealth.lab1;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		// creating button dynamically 
		final Button button = new Button(this);
		button.setText("red");
		LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout);
        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
				layout.setBackgroundColor(Color.RED);  //changes activity's background to red
			}
		});
		ll.addView(button, lp);
	}
	
	// method called by manifest file button 
	public void changeBgToBlue(View view){
		LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
		layout.setBackgroundColor(Color.BLUE); //changes activity's background to Blue
	}

}
